﻿using BaiTu.Framework.Core.StartupTask;
using BaiTu.IDAL;
using BaiTu.IOCServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.DAL.EF.StartUpTask
{
    public class EfStartUpTask : IStartupTask
    {
        public void Execute()
        {
            var settings = BaiTu.Config.DataSettingsConfig.GetConfig();
            if ((settings != null && settings.IsValid()&&Config.DataSettingsConfig.IsDataBaseInstalled==false)||Config.DataSettingsConfig.CreateNewDataBase==true)
            {
                var provider = EngineContext.Current.Resolve<IDataProvider>();
                if (provider == null)
                    throw new Framework.Exceptions.BaiTuCoreException("No IDataProvider found");
                provider.SetDatabaseInitializer();

            }
        }

        public int Order
        {
            //ensure that this task is run first 
            get { return -1000; }
        }
    }
}
